package com.un.ebs.core.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;

/**
 * @author liubo   18855815@qq.com
 * @date 2018-09-10
 * @desc 数据类型定义
 */
@Getter
public enum DataTypeEnum implements IEnum {

    OBJECT(0, "对象", false),
    STRING(1, "字符", false),
    NUMBER(2, "带小数的数值", false),
    INT(3, "整数值", false),
    DATE(4, "日期", false),
    DATETIME(5, "日期时间", false),
    MONEY(6, "金额", false),
    BOOLEAN(7, "逻辑", false),
    RESOURCE_DATA(9, "其它", false),
    NONE(-1, "未知", false);

    @EnumValue
    private final int code;

    private final String desc;

    private boolean jsonIgonre;


    DataTypeEnum(int code, String desc, boolean jsonIgonre) {
        this.code = code;
        this.desc = desc;
        this.jsonIgonre = jsonIgonre;
    }

    @Override
    public int getCode() {
        return code;
    }


    @Override
    public String getDesc() {
        return desc;
    }

    public boolean isJsonIgonre() {
        return jsonIgonre;
    }

    public void setJsonIgonre(boolean jsonIgonre) {
        this.jsonIgonre = jsonIgonre;
    }

    public static DataTypeEnum getEnumByCode(int code) {
        for (DataTypeEnum dataTypeEnum : DataTypeEnum.values()) {
            if (code == dataTypeEnum.getCode()) {
                return dataTypeEnum;
            }
        }
        return null;
    }
}
